package com.editso.haier.controller.user;

import com.editso.haier.result.Result;
import com.editso.haier.service.FutureService;
import com.editso.haier.service.TopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(path = "/list")
public class FutureController {

    private TopicService topicService;

    private FutureService futureService;

    @Autowired
    public void setFuture(FutureService future) {
        this.futureService = future;
    }

    @Autowired
    public void setTopicService(TopicService topicService) {
        this.topicService = topicService;
    }

    @GetMapping("/topic")
    private Result getTopic(Integer id, boolean lazy, boolean cascade, boolean secondary) {
        return id != null
                ? topicService.detailsTopic(id, lazy, secondary)
                : topicService.queryAllTopic(lazy, cascade, null, null, secondary);
    }

    @GetMapping("/tag")
    private Result getTags(){
        return futureService.getTags();
    }

    /**
     * 获取一个主题下的选项
     *
     * @param id      主题id
     * @param exclude 需要排除的选项
     * @return 成功返回 2000 并包含数据
     */
    @GetMapping("/secondary")
    public Result getSecondary(@RequestParam Integer id, String exclude) {
        return futureService.findSecondary(id, exclude);
    }

    /**
     * 商品搜索
     * @param topicId 主题
     * @param filter  过滤
     */
    @GetMapping("/search")
    public Result search(@RequestParam String topicId,
                         @RequestParam(defaultValue = "0") Integer page,
                         @RequestParam(defaultValue = "50") Integer size,
                         @RequestParam(defaultValue = "") String filter) {
        return futureService.search(topicId, filter, page, size);
    }

    /**
     * 商品推荐
     * @param type 推荐类型
     * @param filter 过滤
     *               filter=tag(1,2,...):sec(1,2,...):topic(id,id,....)
     * @param count 数量
     * @see com.editso.haier.arg.ArgParser#parse(String)
     */
    @GetMapping("/recommend")
    public Result recommend(@RequestParam(defaultValue = "banner") String type,
                            @RequestParam(defaultValue = "6") Integer count,
                            @RequestParam(defaultValue = "") String filter) {
        return futureService.recommend(type, filter, count);
    }

    @GetMapping("/related")
    public Result related(String assetsName, Integer type, @RequestParam(defaultValue = "1") Integer count){
        return futureService.related(assetsName, count);
    }

}
